﻿@model IEnumerable<zy6.Models.Task>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("添加", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.TaskPriority)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TaskState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FinishedTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.uid)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.TaskPriority)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Content)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AddTime)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.TaskState)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FinishedTime)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.uid)
            </td>
            <td>
                @Html.ActionLink("修改", "Update", new { id = item.TaskID }) |
                @Html.ActionLink("详情", "Detail", new { id = item.TaskID }) |
                @*@Html.ActionLink("删除", "Delete", new { id = item.TaskID },new {del=item.TaskID})*@
                <a href="#" class="btn btn-danger" data-del="@item.TaskID">删除</a>
            </td>
        </tr>
    }

</table>
@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $(this).attr("data-del");
                if (!confirm("你确定要删除吗" + id + "?")) return;
                $.post("Delete", { id: id }, function (res) {
                    if (res == true) {
                        $this.closest("tr").remove();
                        alert("删除成功");

                    }
                });
            })
        })
    </script>
    }